/**
 * Created by Eoly on 2016/12/31.
 */
function WeaponPack() {
    var _this = this;

    _this.shootHandle = 0;

    //需要外部赋值
    _this.playerBelongs
        = null;
    _this.centrePoint
        = null;
    _this.canvas
        = null;

    //需调用set函数初始化
    _this.bullets = [];
    _this.frequencyFiring = 300;
    _this.clip = 999999;  //弹夹
    _this.isUsedOff = false;

    _this.init = function () {
        _this.bullets.push(
            Bullet
        )
    };
    _this.init();

}
WeaponPack.prototype = {


    setBullets:function (bullet,i) {
        bullet.modelUsed.isFaceDeg = true;
    },

    shoot: function (userOffBack) {
        // console.log(this.bullets);
        if (this.clip > 0) {
            for (var i in this.bullets) {
                var bullet = new this.bullets[i];
                bullet.playerBelongs = this.playerBelongs;
                bullet.setCentrePoint(this.centrePoint);
                this.setBullets(bullet,i);
                bullet.isShooted = true;
                bullet.setBulletCanvas(this.canvas);
            }
            this.clip--;
            if(this.playerBelongs.id == 0)
                player.writeInfo();
            if (this.clip <= 0) {
                this.endOfShoot();
                this.isUsedOff = true;
                userOffBack();
            }
        }
    },

    startShoot: function (userOffBack) {
        var _this = this;
        _this.shoot(userOffBack);
        this.shootHandle = setInterval(function () {
            _this.shoot(userOffBack);
        }, _this.frequencyFiring);
    },

    endOfShoot: function () {
        clearInterval(this.shootHandle);
    }

};

function RandomPack() {
    //不规律角度连发弹药包
    var _this = this;
    WeaponPack.call(this);
    _this.frequencyFiring = 50;
    _this.clip = 500;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            RandomBullet
        )
    };
    _this.init();
}
Extend(WeaponPack, RandomPack);
RandomPack.prototype.setBullets = function (bullet,i) {
    bullet.modelUsed.isFaceDeg = true;
    bullet.runningTrack.direction = 30 * (Math.random() - 0.5);
};

function RayPack() {
    //光弹
    var _this = this;
    WeaponPack.call(this);
    _this.clip = 100;
    _this.frequencyFiring = 500;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            RayBullet
        )
    };
    _this.init();
}
Extend(WeaponPack, RayPack);

function RandomSPack() {
    //不规律弹包
    var _this = this;
    WeaponPack.call(this);
    _this.clip = 400;
    _this.frequencyFiring = 50;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            RandomSBullet
        )
    };
    _this.init();
}
Extend(WeaponPack, RandomSPack);

function ShotPack() {
    //散弹
    var _this = this;
    WeaponPack.call(this);
    _this.clip = 30;
    _this.frequencyFiring = 2000;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            Bullet, Bullet, Bullet, Bullet, Bullet, Bullet, Bullet, Bullet, Bullet, Bullet
        )
    };
    _this.init();
}
Extend(WeaponPack, ShotPack);
ShotPack.prototype.setBullets = function (bullet,i) {
    bullet.modelUsed.isFaceDeg = true;
    bullet.runningTrack.direction = 90 / this.bullets.length * (i - this.bullets.length / 2);
};

function EnemyFallowPack() {
    var _this = this;
    WeaponPack.call(this);
    _this.frequencyFiring = 2000;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            EnemyFollowBullet
        )
    };
    _this.init();
}
Extend(WeaponPack, EnemyFallowPack);

function EnemyNormalPack() {
    var _this = this;
    WeaponPack.call(this);
    _this.frequencyFiring = 5000;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            EnemyNormalBullet
        )
    };
    _this.init();
}
Extend(WeaponPack, EnemyNormalPack);
EnemyNormalPack.prototype.setBullets = function (bullet,i) {
    bullet.modelUsed.isFaceDeg = true;
    var p1 = this.centrePoint;
    var p2 = player.plane != null ? player.plane.centrePoint : new Point(0, 100);
    bullet.runningTrack.direction = p1.getDegFromAnotherPoint(p2);
};


function RandomFallowPack() {
    //不规律角度连发弹药包
    var _this = this;
    RandomPack.call(this);
    _this.frequencyFiring = 3000;
    _this.clip = 25;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            RandomFollowBullet,RandomFollowBullet
        )
    };
    _this.init();
}
Extend(RandomPack, RandomFallowPack);

function DefensePack() {
    //不规律角度连发弹药包
    var _this = this;
    RandomPack.call(this);
    _this.frequencyFiring = 500;
    _this.clip = 50;
    _this.init = function () {
        _this.bullets = [];
        _this.bullets.push(
            DefenseBullet
        )
    };
    _this.init();
}
Extend(RandomPack, DefensePack);

